package com.tanhua.server.controller;

import com.tanhua.model.domain.Answers;
import com.tanhua.model.vo.QuestionnaireVo;
import com.tanhua.model.vo.ReportVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author pc
 * @date 2021/11/27
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;

    /**
     * 查询问卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity getList() {
        List<QuestionnaireVo> questionnaireVos = testSoulService.getQuestionnaires();
        return ResponseEntity.ok(questionnaireVos);
    }

    /**
     * 提交问卷答案
     * @param answer
     * @return
     */
    @PostMapping
    public ResponseEntity submit(@RequestBody Map<String, List<Answers>> answer) {
        List<Answers> answers = answer.get("answers");
        String reportId = testSoulService.submit(answers);
        return ResponseEntity.ok(reportId);
    }

    /**
     * 查看问卷报告
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity look(@PathVariable String id){
        Integer reportId = Integer.valueOf(id);
        ReportVo reportVo = testSoulService.look(reportId);
        return ResponseEntity.ok(reportVo);
    }

}
